package huawei;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 最小步数组合
 */
public class Q29 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        Integer N = sc.nextInt();
        sc.close();

        List<Integer> collect = Arrays.stream(s.substring(1, s.length() - 1).split(",")).map(String::trim).map(Integer::parseInt).collect(Collectors.toList());


        List<int[]> result = new ArrayList<>();
        for (int i = 0; i < collect.size(); i++) {
            int n = N - collect.get(i);
            for (int j = i + 1; j < collect.size(); j++) {
                if (n == collect.get(j)) {
                    result.add(new int[]{i + j, collect.get(i), collect.get(j)});
                }
            }
        }

        if (!result.isEmpty()) {
            result.sort(Comparator.comparing(o -> o[0]));
            System.out.println("["+result.get(0)[1] +", "+ result.get(0)[2]  +"]");
        }

    }
}
